import {
  FETCH_BING_PHOTOS_PENDING,
  FETCH_BING_PHOTOS_SUCCESS,
  FETCH_BING_PHOTOS_FAILURE
} from './types'
const initialState: IAnyArray = []

export const bingPhotos = (state = initialState, action: IAction) => {
  if (action.payload === undefined) {
    action.payload = []
  }

  switch (action.type) {
    case FETCH_BING_PHOTOS_PENDING:
      return [...state, ...action.payload]
    case FETCH_BING_PHOTOS_SUCCESS:
      return action.payload.images[0]
    case FETCH_BING_PHOTOS_FAILURE:
      return {
        error: true,
        payload: {
          message: action.payload.message
        }
      }
    default:
      return state
  }
}
